package com.neulogistics.contrib.warehouse.api.application.converter;

import cn.hutool.json.JSONUtil;
import com.neulogistics.contrib.warehouse.api.application.viewmodel.WarehouseViewModel;
import com.neulogistics.contrib.warehouse.domain.model.valueobject.Address;
import com.neulogistics.contrib.warehouse.infrastructure.persistence.orm.po.WarehousePO;
import org.springframework.beans.BeanUtils;

public class WarehousePOVMConverter {
    public static WarehouseViewModel POToVM(WarehousePO po){
        if(po == null)
            return null;

        WarehouseViewModel viewModel = new WarehouseViewModel();
        BeanUtils.copyProperties(po, viewModel);
        viewModel.setWarehouseAddress(JSONUtil.toBean(po.getWarehouseAddress(), Address.class));
        return viewModel;
    }
}
